
	clear

	
	use "Data/Raw/endline_2_merged.dta"
	
	
* Generate variables

	* Clean party ID
	
		gen partyID_endline2=0 if inparty=="Democrat"
			replace partyID_endline2=1 if inparty=="Republican"
		
			cap la def partyID_endline2 0 "Democrat" 1 "Republican"
			la val partyID_endline2 partyID_endline2
			la var partyID_endline2 "Endline 2: Party ID"
				
			destring partisanship, replace
		gen partyID_endline2_alt=0 if partisanship==2
			replace partyID_endline2_alt=1 if partisanship==1
			replace partyID_endline2_alt=2 if partisanship==3
			
			replace partyID_endline2_alt=0 if partisanship_4_text=="green"
			replace partyID_endline2_alt=0 if partisanship_4_text=="Green"
			replace partyID_endline2_alt=0 if partisanship_4_text=="progressive"
			replace partyID_endline2_alt=0 if partisanship_4_text=="Progressive"
			replace partyID_endline2_alt=0 if partisanship_4_text=="I would be independent but with a lack of ranked voting; I'm effectively Democrat"
				replace partyID_endline2_alt=0 if email_merged=="jk@grose.io"
			replace partyID_endline2_alt=0 if partisanship_4_text=="I am mostly a democrat but really don't fit into these categories"
				replace partyID_endline2_alt=0 if email_merged=="iankleiman@gmail.com"
								
			replace partyID_endline2_alt=1 if partisanship_4_text=="Conservative Unaffiliated"
			replace partyID_endline2_alt=1 if partisanship_4_text=="Libertarian "
			replace partyID_endline2_alt=1 if partisanship_4_text=="Libertarian"
			replace partyID_endline2_alt=1 if partisanship_4_text=="Former Republican"
			replace partyID_endline2_alt=1 if partisanship_4_text=="I was a R all of my life until Trump ran. I could not support him or his views. I consider my self an old line moderate R of the old school. Talk to the other side and agree to something!"
				replace partyID_endline2_alt=1 if email_merged=="lindabarnet@gmail.com"
			replace partyID_endline2_alt=1 if partisanship_4_text=="none or Classical Liberal"
				
			replace partyID_endline2_alt=2 if partisanship_4_text=="Politically homeless"
			replace partyID_endline2_alt=2 if partisanship_4_text=="Politically Homeless"
			replace partyID_endline2_alt=2 if partisanship_4_text=="Radical centrist"
			replace partyID_endline2_alt=2 if partisanship_4_text=="Unaffiliated"
				
			replace partyID_endline2_alt=2 if partisanship_4_text=="" & partisanship==4
				
			cap la def partyID_endline2_alt 0 "Democrat" 1 "Republican" 2 "Independent"
			la val partyID_endline2_alt partyID_endline2_alt
			la var partyID_endline2_alt "Endline 2: Party ID (with Independents)"
							
							
							
	* Generate inparty vs. outparty feeling thermometer
	
			foreach x of varlist therm_inparty therm_outparty {
				destring `x', replace
			}
			
		gen therm_diff = therm_inparty-therm_outparty
			la var therm_diff "Endline 2: Inparty vs. outparty feeling thermometer"
		
		gen therm_cool_inparty = 100-therm_inparty
			la var therm_cool_inparty "Endline 2: Inparty coolness"

		gen therm_cool_outparty = 100-therm_outparty
			la var therm_cool_outparty "Endline 2: Outparty coolness"

			
	* Generate negative partisanship dummy
			
			destring val_neg_part, replace
		gen neg_partisan = (val_neg_part==4) if val_neg_part!=.
			la var neg_partisan "Endline 2: Negative partisanship"
	
	
	
	* Generate inparty vs. outparty trust
	
		foreach x of varlist trust_inparty trust_outparty {
			destring `x', replace
		}
	
		gen trust_diff = trust_inparty - trust_outparty
			la var trust_diff "Endline 2: Inparty vs. outparty trust"

		gen distrust_inparty = 6-trust_inparty
			la var distrust_inparty "Endline 2: Inparty distrust"

		gen distrust_outparty = 6-trust_outparty
			la var distrust_outparty "Endline 2: Outparty distrust"
	
	* Generate comfort with outparty
	
		foreach x of varlist val_close_friends val_neighbor val_marriage {
			destring `x', replace
		}
	
		gen comfort_outparty_friends =  val_close_friends
		gen comfort_outparty_neighbors = val_neighbor
		gen comfort_outparty_marriage = val_marriage
	
	* Generate threat perceptions 
	
		foreach x of varlist val_prop_citizens val_prop_pols {
			destring `x', replace
		}

		gen threat_outparty_cit = val_prop_citizens 
		gen threat_outparty_pol = val_prop_pols 
	
	* Generate affective polarization index
	
			
		alpha therm_diff neg_partisan trust_diff comfort_outparty_friends comfort_outparty_neighbors comfort_outparty_marriage threat_outparty_cit threat_outparty_pol, std item detail gen(aff_pol_idx_temp)
			egen aff_pol_idx = std(aff_pol_idx_temp)
				la var aff_pol_idx "Endline 2: Attitudinal affective polarization index"
					drop aff_pol_idx_temp
		
		alpha therm_cool_outparty neg_partisan distrust_outparty comfort_outparty_friends comfort_outparty_neighbors comfort_outparty_marriage threat_outparty_cit threat_outparty_pol, std item detail gen(aff_pol_idx_out_temp)
			egen aff_pol_idx_out = std(aff_pol_idx_out_temp)
				la var aff_pol_idx_out "Endline 2: Attitudinal affective polarization index (outparty only)"
					drop aff_pol_idx_out_temp

		alpha therm_diff trust_diff comfort_outparty_friends comfort_outparty_neighbors comfort_outparty_marriage threat_outparty_cit threat_outparty_pol, std item detail gen(aff_pol_idx_noneg_temp)
			egen aff_pol_idx_noneg = std(aff_pol_idx_noneg_temp)
				la var aff_pol_idx_noneg "Endline 2: Attitudinal affective polarization index (no negative partisanship)"
					drop aff_pol_idx_noneg_temp
				
		alpha therm_cool_outparty distrust_outparty comfort_outparty_friends comfort_outparty_neighbors comfort_outparty_marriage threat_outparty_cit threat_outparty_pol, std item detail gen(aff_pol_idx_noneg_out_temp)
			egen aff_pol_idx_noneg_out = std(aff_pol_idx_noneg_out_temp)
				la var aff_pol_idx_noneg_out "Endline 2: Attitudinal affective polarization index (outparty only, no negative partisanship)"
					drop aff_pol_idx_noneg_out_temp
			
			
	* Clean antidemocratic attitudes 
	
		foreach x of varlist antidem_* {
			destring `x', replace
		}
			
	
		foreach x of varlist antidem_1 antidem_3 antidem_4 antidem_6 {
			gen `x'_rec = `x'
				replace `x'_rec=5-`x'_rec
		}
	
			alpha antidem_1_rec antidem_2 antidem_3_rec antidem_4_rec antidem_5 antidem_6_rec, std item detail gen(antidem_idx_temp)
				egen antidem_idx = std(antidem_idx_temp)
					la var antidem_idx "Endline 2: Anti-democratic attitudes"
						drop antidem_idx_temp
	
	
	
	* Clean tolerance for racism and misinformation
		
			foreach x of varlist mis1_rep mis2_rep mis3_rep mis1_dem mis2_dem mis3_dem ///
				race1_rep race2_rep race3_rep race1_dem race2_dem race3_dem {
				destring `x', replace
			}
		
		gen race_multi = race3_dem
			replace race_multi = race3_rep if race_multi==.
			la def race_mis_multi 1 "Intervene if skilled" 2 "Intervene regardless" 3 "Ignore"
			la val race_multi race_mis_multi
			
		gen mis_multi = mis3_dem
			replace mis_multi = mis3_rep if mis_multi==.
			la val mis_multi race_mis_multi
		
		gen race_mis_multi_either = 1 if race_multi==1 | mis_multi==1
			replace race_mis_multi_either = 2 if race_multi==2 | mis_multi==2
			replace race_mis_multi_either = 3 if race_multi==3 | mis_multi==3
			la val race_mis_multi_either race_mis_multi
		
		foreach n of numlist 1 2 {
			gen tol_misinfo`n'=1-mis`n'_dem
				replace tol_misinfo`n'=1-mis`n'_rep if tol_misinfo`n'==.
			gen tol_racism`n'=1-race`n'_dem
				replace tol_racism`n'=1-race`n'_rep if tol_racism`n'==.
			
			gen confront_misinfo`n' = mis`n'_dem
				replace confront_misinfo`n'=mis`n'_rep if confront_misinfo`n'==.
			gen confront_racism`n' = race`n'_dem
				replace confront_racism`n'=race`n'_rep if confront_racism`n'==.
				
			}
				
		alpha confront_misinfo1 confront_misinfo2, std item detail gen(confront_misinfo_idx_temp)
			egen confront_misinfo_idx = std(confront_misinfo_idx_temp)

		alpha confront_racism1 confront_racism2, std item detail gen(confront_racism_idx_temp)
			egen confront_racism_idx = std(confront_racism_idx_temp)
		
		alpha confront_racism1 confront_racism2 confront_misinfo1 confront_misinfo2, std item detail gen(confront_rac_mis_idx_temp)
			egen confront_rac_mis_idx = std(confront_rac_mis_idx_temp)

		gen tol_misinfo3 = (mis3_dem==3 | mis3_rep==3)
			replace tol_misinfo3=. if mis3_dem==. & mis3_rep==.
		
		gen tol_racism3 = (race3_dem==3 | race3_rep==3)
			replace tol_racism3=. if race3_dem==. & race3_rep==.
		
		gen confront_misinfo3 = 1-tol_misinfo3
		gen confront_racism3 = 1-tol_racism3
	
		alpha confront_misinfo1 confront_misinfo2 confront_misinfo3, std item detail gen(confront_misinfo_idx_alt_temp)
			egen confront_misinfo_idx_alt = std(confront_misinfo_idx_alt_temp)
		
		alpha confront_racism1 confront_racism2 confront_racism3, std item detail gen(confront_racism_idx_alt_temp)
			egen confront_racism_idx_alt = std(confront_racism_idx_alt_temp)
		
		alpha confront_racism1 confront_racism2 confront_racism3 confront_misinfo1 confront_misinfo2 confront_misinfo3, std item detail gen(confront_rac_mis_idx_alt_temp)
			egen confront_rac_mis_idx_alt = std(confront_rac_mis_idx_alt_temp)

		
		
		
	* Clean trust game
	
		foreach x of varlist trust_dem* trust_rep* {
			cap destring `x', replace
		}

		foreach n of numlist 1/10 {
			gen trust_`n'=trust_dem_`n'
				replace trust_`n'=trust_rep_`n' if trust_`n'==.
		}
				
		gen trust_allmiss=(trust_1==. & trust_2==. & trust_3==. & trust_4==. & trust_5==. & trust_6==. & trust_7==. & trust_8==. & trust_9==. & trust_10==.)
	
		gen trust_anymiss=(trust_1==. | trust_2==. | trust_3==. | trust_4==. | trust_5==. | trust_6==. | trust_7==. | trust_8==. | trust_9==. | trust_10==.) if trust_allmiss==0
	
		foreach n of numlist 1/10 {
			gen trust_`n'_miss = (trust_`n'==.) if trust_allmiss==0
		}
		
		egen trust_nummiss = rowtotal(trust_1_miss trust_2_miss trust_3_miss trust_4_miss trust_5_miss trust_6_miss trust_7_miss trust_8_miss trust_9_miss trust_10_miss) if trust_allmiss==0
			
		gen trust_1_pr = trust_1/3
		gen trust_2_pr = trust_2/6
		gen trust_3_pr = trust_3/9
		gen trust_4_pr = trust_4/12
		gen trust_5_pr = trust_5/15
		gen trust_6_pr = trust_6/18
		gen trust_7_pr = trust_7/21
		gen trust_8_pr = trust_8/24
		gen trust_9_pr = trust_9/27
		gen trust_10_pr = trust_10/30
		
		egen trust_total_pr = rowtotal(trust_1_pr trust_2_pr trust_3_pr trust_4_pr trust_5_pr trust_6_pr trust_7_pr trust_8_pr trust_9_pr trust_10_pr)
			foreach n of numlist 0/9 {
				replace trust_total_pr = trust_total_pr/(10-`n') if trust_nummiss==`n'
			}
			
			replace trust_total_pr=. if trust_allmiss==1
					
			la var trust_total_pr "Endline 2: Avg. % expected donation in trust game"
		

		
	* Clean petitions 
	
		gen signed_inter_pet = (pet_inter_1!="" & pet_inter_1!="NA")
			replace signed_inter_pet=. if progress==.
			replace signed_inter_pet=. if progress<90
			
		gen signed_intra_pet = (pet_intra_1!="" & pet_intra_1!="NA")
			replace signed_intra_pet=. if progress==.
			replace signed_intra_pet=. if progress<90
		
		gen signed_either_pet = (signed_inter_pet==1 | signed_intra_pet==1)
			replace signed_either_pet=. if signed_inter_pet==. & signed_intra_pet==.
		
		gen signed_inter_pet_strict = (pet_inter_1!="" & pet_inter_1!="NA")
			replace signed_inter_pet_strict=. if progress==.
			replace signed_inter_pet_strict=. if progress<90
			replace signed_inter_pet_strict=0 if pet_inter_1=="Amber "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Billy"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Carol"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Cat"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Celina M"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Cheryl "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Christiana "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Cynthia "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Dan L"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Ema"
			replace signed_inter_pet_strict=0 if pet_inter_1=="G. Hooks"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Glory "
			replace signed_inter_pet_strict=0 if pet_inter_1=="J"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Joseph"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Kary"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Laura"
			replace signed_inter_pet_strict=0 if pet_inter_1=="MICHAEL"
			replace signed_inter_pet_strict=0 if pet_inter_1=="MM"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Mable S"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Maim "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Mary C"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Maurice E"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Mayson"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Michelle"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Mike"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Mike s"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Natasha "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Oliver "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Patricia "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Peter"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Prentiss "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Rebecca"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Rebecca "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Robol"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Ronald"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Sandra "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Stella"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Susan"
			replace signed_inter_pet_strict=0 if pet_inter_1=="TD"
			replace signed_inter_pet_strict=0 if pet_inter_1=="Victor "
			replace signed_inter_pet_strict=0 if pet_inter_1=="Virginia H"		
		
		gen signed_intra_pet_strict = (pet_intra_1!="" & pet_intra_1!="NA")
			replace signed_intra_pet_strict=. if progress==.
			replace signed_intra_pet_strict=. if progress<90
			replace signed_intra_pet_strict=0 if pet_intra_1=="Amber "
			replace signed_intra_pet_strict=0 if pet_intra_1=="Billy"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Carol"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Cat"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Cynthia "
			replace signed_intra_pet_strict=0 if pet_intra_1=="Ema"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Glory "
			replace signed_intra_pet_strict=0 if pet_intra_1=="J"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Joseph"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Kary"
			replace signed_intra_pet_strict=0 if pet_intra_1=="MICHAEL"
			replace signed_intra_pet_strict=0 if pet_intra_1=="MM"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Mary C"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Maurice E"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Mayson "
			replace signed_intra_pet_strict=0 if pet_intra_1=="Melanie"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Mike"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Mike s"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Oliver "
			replace signed_intra_pet_strict=0 if pet_intra_1=="Patricia "
			replace signed_intra_pet_strict=0 if pet_intra_1=="Prentiss "
			replace signed_intra_pet_strict=0 if pet_intra_1=="Rebecca "
			replace signed_intra_pet_strict=0 if pet_intra_1=="Robol"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Ronald"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Stella"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Sufia "
			replace signed_intra_pet_strict=0 if pet_intra_1=="TD"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Victor"
			replace signed_intra_pet_strict=0 if pet_intra_1=="Virginia H"		
		
		gen signed_either_pet_strict = (signed_inter_pet_strict==1 | signed_intra_pet_strict==1)
			replace signed_either_pet_strict=. if signed_inter_pet_strict==. & signed_intra_pet_strict==.
		
	* Clean contact with outparty
		
		destring cross_interact, replace
		
		gen cross_interact_freq = 1 if cross_interact==11
			replace cross_interact_freq = 2 if cross_interact==21
			replace cross_interact_freq = 3 if cross_interact==18
			replace cross_interact_freq = 4 if cross_interact==19
			replace cross_interact_freq = 5 if cross_interact==20
		
		gen cross_interact_freq_dum = (cross_interact==18 | cross_interact==19 | cross_interact==20) if cross_interact!=.
		
			destring convo_6mos, replace
		gen cross_interact_last6_any = (convo_6mos!=4) if convo_6mos!=.
			la var cross_interact_last6_any "Endline 2: Any contact with out-partisans in last 6 months"

		gen cross_interact_last6_freq = (convo_6mos==1 | convo_6mos==2) if convo_6mos!=.
			la var cross_interact_last6_freq "Endline 2: Weekly or monthly contact with out-partisans in last 6 months"
		
		gen cross_interact_last6_idx = 5-convo_6mos
			egen cross_interact_last6_idx_std = std(cross_interact_last6_idx)
			drop cross_interact_last6_idx
			ren cross_interact_last6_idx_std cross_interact_last6_idx
			la var cross_interact_last6_idx "Endline 2: Frequency of contact with out-partisans in last 6 months"
		
		
		
	* Clean quality of contact with outparty
	
			destring cross_infostress, replace
		gen cross_stressful = (cross_infostress==2) if cross_infostress!=.
		
			destring qual_intergroup_1, replace
		gen cross_heated = (qual_intergroup_1==2) if qual_intergroup_1!=.
			replace cross_heated = 0 if convo_6mos == 4
		
			destring qual_intergroup_2, replace
		gen cross_angry = (qual_intergroup_2==1) if qual_intergroup_2!=.
			replace cross_angry = 0 if convo_6mos == 4
		
		gen cross_heated_angry = (cross_heated==1 | cross_angry==1)
			replace cross_heated_angry=. if cross_heated==. & cross_angry==.
		
		gen cross_no_heated_angry = (cross_heated==0 & cross_angry==0)
			replace cross_no_heated_angry=. if cross_heated==. & cross_angry==.
		
	* Clean preference for interacting with outparty

		destring cross_grouppref, replace
	
		gen cross_grouppref_inparty = (cross_grouppref==1) if cross_grouppref!=.
			la var cross_grouppref_inparty "Endline 2: Would prefer interacting with ingroup in future"

		gen cross_grouppref_outparty = (cross_grouppref==2) if cross_grouppref!=.
			la var cross_grouppref_outparty "Endline 2: Would prefer interacting with outgroup in future"
		
		gen cross_grouppref_out_mixed = (cross_grouppref!=1) if cross_grouppref!=.
			la var cross_grouppref_out_mixed "Endline 2: Would prefer interacting with mixed or outgroup in future"
		
	
		
	* Generate issue importance index
	
			foreach x of varlist immigration_imp abortion_imp gun_imp {
				destring `x', replace
			}
	
		alpha immigration_imp abortion_imp gun_imp, std item detail gen(issue_imp_idx_temp)
			egen issue_imp_idx = std(issue_imp_idx_temp)
				la var issue_imp_idx "Endline 2: Issue importance index"
					drop issue_imp_idx_temp
	
	
	* Generate political moderation index
	
			destring lib_con_scale_1, replace
	
			gen pol_mod_idx = lib_con_scale_1-4
				replace pol_mod_idx = 3-abs(pol_mod_idx)
				egen pol_mod_idx_std = std(pol_mod_idx)
	
		
	* Clean skills questions
		
			foreach x of varlist sbd_reps sbd_dem dw_reps dw_dem {
				destring `x', replace
			}
		
			foreach x in sbd dw {
				gen `x'_skills_dum = (`x'_reps==1) if `x'_reps!=.
					replace `x'_skills_dum = 1 if `x'_dem==1
					replace `x'_skills_dum = 0 if `x'_dem==0
						
			}
	
			gen sbd_dw_skills_dum = (sbd_skills_dum==1 & dw_skills_dum==1) if sbd_skills_dum!=. & dw_skills_dum!=.

			alpha sbd_skills_dum dw_skills_dum, std item detail gen(sbd_dw_skills_idx_temp)
				egen sbd_dw_skills_idx = std(sbd_dw_skills_idx_temp)
			
			

	
	* Clean time between treatment and survey response
	
	
		split startdate, p("-")
			destring startdate1, replace
			destring startdate2, replace
			ren startdate2 endline_start_month
	
		split startdate3, p(" ")
			destring startdate31, replace
			ren startdate31 endline_start_day
		
		split startdate32, p(":")
			destring startdate321, replace
			ren startdate321 endline_start_hour
			
		gen days_since_endline2 = endline_start_day-24 if endline_start_month==10
			replace days_since_endline2 = endline_start_day+7 if endline_start_month==11
		
			
	* Clean time between assigned workshop and survey response
	
		gen days_bw_workshop_endline2 = endline_start_day+209 if endline_start_month==10 & treat_march5==1
			replace days_bw_workshop_endline2 = endline_start_day+240 if endline_start_month==11 & treat_march5==1
		
			replace days_bw_workshop_endline2 = endline_start_day+202 if endline_start_month==10 & treat_march12==1
			replace days_bw_workshop_endline2 = endline_start_day+233 if endline_start_month==11 & treat_march12==1

			replace days_bw_workshop_endline2 = endline_start_day+195 if endline_start_month==10 & treat_march19==1
			replace days_bw_workshop_endline2 = endline_start_day+226 if endline_start_month==11 & treat_march19==1

			replace days_bw_workshop_endline2 = endline_start_day+188 if endline_start_month==10 & treat_march26==1
			replace days_bw_workshop_endline2 = endline_start_day+219 if endline_start_month==11 & treat_march26==1
			
			replace days_bw_workshop_endline2 = . if aff_pol_idx_noneg==.
			
			
			
			
	* Clean attendance at BA or other depolarization events
	
		gen any_depol = (demo_ba!="9") if demo_ba!=""
			replace any_depol = 1 if demo_depolarize=="2"
			
			
			
	* Clean demographics
	
		destring demo_gender, replace
	
		gen gender_endline2 = 0 if demo_gender==1
			replace gender_endline2 = 1 if demo_gender==4
			replace gender_endline2 = 2 if demo_gender==2 | demo_gender==5 | demo_gender==7
			
			la def gender_endline2 0 "Man" 1 "Woman" 2 "Other"
			la val gender_endline2 gender_endline2
			
	* Destring variables
	
		foreach x of varlist informed_consent age citizenship lib_con_scale_1 partisanship_force immigration immigration_imp ///
			abortion abortion_imp gun gun_imp cross_talkpol cross_infostress {
				destring `x', replace
			}
			
	* Generate wave indicator
	
		gen wave = 2


	* Redefine attriters as respondents who didn't complete any of the survey

		replace attrition_endline2 = 1 if progress==0
		
	* Redefine attriters as respondents for whom we don't have an affective polarization score
	
		replace attrition_endline2 = 1 if aff_pol_idx_noneg==.

		gen non_attrition_endline2 = 1-attrition_endline2
			

	* Generate IPW
	
		reg non_attrition_endline2 i.treat_control_study2##i.partyID_merged i.treat_control_study2##i.BA_listserv i.treat_control_study2##i.previous_BA_any
			predict fit_bysample
				gen ipw_bysample = 1/fit_bysample		

			
	
* Save
	
	save "Data/Cleaned/endline_2_merged_cleaned.dta", replace

	